package com.example.jpushdemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.TextView;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;
import org.wutao.supernewsapp.R;
import org.wutao.supernewsapp.web.MyWebViewClient;

import cn.jpush.android.api.JPushInterface;

public class TestActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        TextView tv = (TextView) findViewById(R.id.title_test);
        WebView webView = (WebView) findViewById(R.id.web_view);
        //拦截，不跳转自带的浏览器
        webView.setWebViewClient(new MyWebViewClient(null));
        tv.setText("用户自定义打开的Activity");
        Intent intent = getIntent();
        if (null != intent) {
	        Bundle bundle = getIntent().getExtras();
            //通过JPushInterface可以获取所有的字段
	        String title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
	        String content = bundle.getString(JPushInterface.EXTRA_ALERT);
	        tv.setText("Title : " + title + "  " + "Content : " + content);
            //获取附加字段,字符串格式是json
            String json = bundle.getString(JPushInterface.EXTRA_EXTRA);
            if (json != null) {
                try {
                    JSONObject jsonObject = new JSONObject(json);
                    String url = jsonObject.getString("url");
                    Toast.makeText(TestActivity.this, "url"+url, Toast.LENGTH_SHORT).show();
                    webView.loadUrl(url);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
//        addContentView(tv, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    }


}
